package com.huidao.servlet.user;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Role;
import com.huidao.entity.User;
import com.huidao.service.UserService;
import com.huidao.service.UserServiceImpl;

/**
 * Servlet implementation class UpdateUserServlet
 */
public class UpdateUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = new User();
		user.setUserId(Long.parseLong(request.getParameter("id")));
		user.setUserName(request.getParameter("name"));
		user.setUserPassword(request.getParameter("password"));
		Role role = new Role();
		role.setRoleId(Long.parseLong(request.getParameter("roleId")));
		user.setRole(role);
		UserService s = new UserServiceImpl();
		String data = s.updateUser(user);
		if(data.equals("")){
			response.sendRedirect("GetUserListServlet");
		}else{
			response.getWriter().print(data);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
